package com.cea.papyrus.diagram.composite.figure;

import org.eclipse.draw2d.Graphics;
import org.eclipse.draw2d.PositionConstants;
import org.eclipse.draw2d.geometry.Rectangle;
import org.eclipse.swt.SWT;

/**
 * Figure for Required interface. It draws an half circle.
 */
public class RequiredInterfaceFigure extends ProvidedInterfaceFigure {
	
	/** sets the begining of the arc */
	protected int arcStarting=0;
	
	/**
	 * Sets the orientation of the arc
	 * @param positionConstants position of the interface compared to the port
	 * @see PositionConstants
	 */
	public void setOrientation( int positionConstants){
		if (positionConstants == PositionConstants.NORTH){
			arcStarting=180;
		}
		if (positionConstants == PositionConstants.SOUTH){
			arcStarting=0;
		}
		if (positionConstants == PositionConstants.WEST){
			arcStarting=270;
		}
		if (positionConstants == PositionConstants.EAST){
			arcStarting=90;
		}
		this.repaint();
	}
	
	/* (non-Javadoc)
	 * @see com.cea.papyrus.diagram.composite.figure.ProvidedInterfaceFigure#paintFigure(org.eclipse.draw2d.Graphics)
	 */
	@Override
	public void paintFigure(Graphics graphics) {
		graphics.pushState();
		graphics.setAntialias(SWT.ON); 
		Rectangle area = getBounds();
		graphics.setLineWidth(2);
		graphics.drawArc(area.x+2 , area.y+2, area.width-4, area.height - 4, arcStarting, 180);
		graphics.popState();
		
	}

}
